/* 
 * cms，一个基于J2EE架构内容管理系统
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.service.search.impl;

import org.grayrabbit.cms.dao.search.KeywordsRecommendDao;
import org.grayrabbit.cms.entity.KeywordsRecommend;
import org.grayrabbit.cms.service.search.KeywordsRecommendService;
import org.grayrabbit.cms.vo.search.KeywordsRecommendBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.grayrabbit.dao.util.Page;
import org.grayrabbit.service.impl.GenericServiceImpl;
/**
 * <b>OperLog</b>的service实现类，事务加此处：





 * @version 1.0,创建时间: 2011-10-26 13:42:14  
 */
@Service
@Transactional
public class KeywordsRecommendServiceImpl extends GenericServiceImpl implements KeywordsRecommendService {
	/**
	 * 注入dao层：
	 */
	@Autowired
	@Qualifier("keywordsRecommendDaoImpl")
	private KeywordsRecommendDao keywordsRecommendDao;
	
	/**
	 * 此方法执行时为只读事务：
	 * @see KeywordsRecommendService#getOperLog(String)
	 */
	@Transactional(readOnly=true)
	public KeywordsRecommend getKeywordsRecommend(final String kwrecommendId){
		KeywordsRecommend keywordsRecommend = keywordsRecommendDao.findById(kwrecommendId);
		keywordsRecommendDao.initialize(keywordsRecommend);
		return keywordsRecommend;
	}
	
	/**
	 * @see KeywordsRecommendService#delete(String)
	 */
	@Transactional
	public void delete(final KeywordsRecommend keywordsRecommend) {
		keywordsRecommendDao.makeTransient(keywordsRecommend);
	}
	
	/**
	 * @see KeywordsRecommendService#save(OperLog)
	 */
	@Transactional
	public void save(final KeywordsRecommend keywordsRecommend) {
		keywordsRecommendDao.makePersistent(keywordsRecommend);		
	}
	
	/**
	 * 此方法执行时为只读事务：
	 * @see KeywordsRecommendService#getPage(KeywordsRecommendBean)
	 */
	@Transactional(readOnly=true)
	public Page<KeywordsRecommend> getPage(final KeywordsRecommendBean keywordsRecommendBean){
		Page<KeywordsRecommend> page =  new Page<KeywordsRecommend>();
		page.setTotal(keywordsRecommendDao.count(keywordsRecommendBean));
		page.setResult(keywordsRecommendDao.findByQc(keywordsRecommendDao.assembly(keywordsRecommendBean)));
		return page;
	}

	/**
	 * 此方法执行时为只读事务：
	 * @see KeywordsRecommendService#list(Page, KeywordsRecommendBean)
	 */
	public void list(Page<KeywordsRecommend> page, KeywordsRecommendBean keywordsRecommendBean) {
		if(page==null)
			return;
		if(page.isAutoCount()){
			page.setTotal(keywordsRecommendDao.count(keywordsRecommendBean));
		}
		page.setResult(keywordsRecommendDao.findByPage(page,keywordsRecommendBean));
	}
	
	/**
	 * 根据主键id列删除，批量删除OperLog
	 * @see KeywordsRecommendService#delete(String[])
	 */
	public void delete(final String[] key) {
		int i =0;
		for(String id : key){
			keywordsRecommendDao.makeTransient(keywordsRecommendDao.findById(id));
			i++;
			if(i==MAX_CLEAR)
				keywordsRecommendDao.clear();
		}
		
	}

	public boolean isExistUrl(String id, String url) {
		return keywordsRecommendDao.isExistUrl(id, url);
	}
 
}